﻿using FriendStar.Code;
using FriendStar.Domain.Entity.VBaseData;
using FriendStar.Domain.IRepository.VBaseData;
using FriendStar.Repository.VBaseData;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;

namespace FriendStar.Application.VBaseData
{
    public class V_CPK_45_HZ_StoCPKListAccoApp
    {
        private IV_CPK_45_HZ_StoCPKListAccoRepository service = new V_CPK_45_HZ_StoCPKListAccoRepository();

        public List<V_CPK_45_HZ_StoCPKListAccoEntity> GetList()
        {
            return service.IQueryable().ToList();
        }
        public List<V_CPK_45_HZ_StoCPKListAccoEntity> GetParameterGridJson(Pagination pagination, string companyname, string productionno, string fcurdate, string fvoucherno, string ledgerdate)
        {
            var expression = ExtLinq.True<V_CPK_45_HZ_StoCPKListAccoEntity>();
            if (!string.IsNullOrEmpty(companyname))
            {
                expression = expression.And(t => t.FProCompanyName.Contains(companyname));
            }
            if (!string.IsNullOrEmpty(productionno))
            {
                expression = expression.And(t => t.FProductionNO.Contains(productionno));
            }
            if (!string.IsNullOrEmpty(fcurdate))
            {
                expression = expression.And(t => t.FCurDate.Contains(fcurdate));
            }
            if (!string.IsNullOrEmpty(fvoucherno))
            {
                expression = expression.And(t => t.FCredence.Contains(fvoucherno));
            }
            if (!string.IsNullOrEmpty(ledgerdate))
            {
                expression = expression.And(t => t.FAccountDate.Contains(ledgerdate));
            }
            expression = expression.And(t => t.FDocuTypeNO == "CR");
            return service.FindList(expression, pagination).OrderBy(t=>t.UseUnit).ToList();
        }
        public List<V_CPK_45_HZ_StoCPKListAccoEntity> GetOutParameterGridJson(Pagination pagination, string companyname, string productionno, string fcurdate, string fvoucherno, string ledgerdate)
        {
            var expression = ExtLinq.True<V_CPK_45_HZ_StoCPKListAccoEntity>();
            if (!string.IsNullOrEmpty(companyname))
            {
                expression = expression.And(t => t.FProCompanyName.Contains(companyname));
            }
            if (!string.IsNullOrEmpty(productionno))
            {
                expression = expression.And(t => t.FProductionNO.Contains(productionno));
            }
            if (!string.IsNullOrEmpty(fcurdate))
            {
                expression = expression.And(t => t.FCurDate.Contains(fcurdate));
            }
            if (!string.IsNullOrEmpty(fvoucherno))
            {
                expression = expression.And(t => t.FCredence.Contains(fvoucherno));
            }
            if (!string.IsNullOrEmpty(ledgerdate))
            {
                expression = expression.And(t => t.FAccountDate.Contains(ledgerdate));
            }
            expression = expression.And(t => t.FDocuTypeNO=="CC");
            return service.FindList(expression, pagination).OrderBy(t => t.UseUnit).ToList();
        }
    }
}

